package com.group.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.base.view.BaseResult;
import com.base.view.GeneralResult;
import com.base.view.ListResult;
import com.group.model.Suggestion;

/**
 * 意见反馈管理
 * 
 * @author zhaolei
 *
 */
@Controller
public class SuggestionController extends BaseController {

	/**
	 * 添加意见反馈
	 * 
	 * @param suggestion
	 * @return
	 */
	@PostMapping("/suggestion/add")
	@ResponseBody
	public GeneralResult<Suggestion> addSuggestion(@RequestBody Suggestion suggestion) {
		beanDao.save(suggestion);

		return new GeneralResult<Suggestion>().setValue(suggestion);
	}

	/**
	 * 删除意见反馈
	 * 
	 * @param suggestionId
	 * @return
	 */
	@DeleteMapping("/suggestion/add")
	@ResponseBody
	public BaseResult deleteSuggestion(Long suggestionId) {
		beanDao.quickDelete(Suggestion.class, "id", suggestionId);

		return new BaseResult();
	}

	/**
	 * 查询意见反馈列表
	 * 
	 * @param key
	 * @param start
	 * @param limit
	 * @return
	 */
	@GetMapping("/suggestion/query")
	@ResponseBody
	public ListResult<Suggestion> querySuggestion(String key, Integer start, Integer limit) {

		return new ListResult<Suggestion>().setList(newsDao.querySuggestion(key, start, limit)).setTotal(newsDao.querySuggestionCount(key));
	}

}
